﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Webdisk;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Webdisk_New
{
	public partial class UserHome : Form
	{
		bool AllFilePitch = false;//所有文件
		bool DFilePitch = false;//文档
		bool PictureFilePitch = false;//图片
		bool MusicFilePitch = false;//音乐
		bool VideoFilePitch = false;//视频
		bool OtherFilePitch = false;//其他
		bool AddUserPitch = false;//添加用户
		bool UserFilePitch = false;//文件管理

		private void Pitch(bool PitchVariable)//选中
		{
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = false;
			PitchVariable = true;
		}
		private Point mPoint;
		string FileExt = "";//文件后缀名
		string FileName = "";//文件名

		string str;//得到修改内容
		string frist;//得到id
		string name;
		string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
        bool isNull = false;
		string userId = null;
        string UserID = "";
        static TcpClient TcpClient;//创建监听
        bool IsMin=false;
		FileStream fs;//路径

		static double AllFileSize = 0;//总的内存

		private void AllFileSizeShow()//显示内存信息
		{
			DBHelper.Conn.Close();

			string a = DBHelper.ExecusteScalar(string.Format("select sum(FileSize) from Information where loginName='{0}'", Temp.TmeploginName)).ToString();
			if (a == "")
			{
				AllFileSizeBar.Value = 0;
				AllFileSizelabel.Text = "100%";
			}
			else
			{

				AllFileSize = double.Parse(a);
				AllFileSizeBar.Value = (int)AllFileSize;
				AllFileSizelabel.Text = (AllFileSize / AllFileSizeBar.Maximum * 100).ToString("0.00") + "%";
			}



			DBHelper.Conn.Close();
		}


		private void PressDown(PictureBox name)//按下
		{
			AllFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AllFile初始.png ");
			DFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\DFile初始.png ");
			PictureFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\PictureFile初始.png ");
			MusicFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\MusicFile初始.png ");
			VideoFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\VideoFile初始.png ");
			OtherFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\OtherFile初始.png ");
			AddUser.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AddUser初始.png ");
			UserFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\UserFile初始.png ");
			name.Image = Image.FromFile(ThePath + string.Format("\\..\\..\\pic\\{0}按下.png ", name.Name));
		}

		private void LeaveType(bool Pitch, PictureBox name)
		{
			if (Pitch == true)
			{
				name.Image = Image.FromFile(ThePath + string.Format("\\..\\..\\pic\\{0}按下.png ", name.Name));
			}
			else
			{
				name.Image = Image.FromFile(ThePath + string.Format("\\..\\..\\pic\\{0}初始.png ", name.Name));
			}
		}


		//设置窗口外阴影
		private const int CS_DropSHADOW = 0x20000;
		private const int GCL_STYLE = (-26);
		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern int GetClassLong(IntPtr hwnd, int nIndex);

		public UserHome()
		{
			InitializeComponent();
			Control.CheckForIllegalCrossThreadCalls = false;

			//设置窗口外阴影
			SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
		}
		//private Point mPoint;





		private void Form1_Load(object sender, EventArgs e) //页面加载事件
		{
            //PalletIcon.Visible = true;
            //PalletIcon.ShowBalloonTip(10, "文件下载完毕", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.None);



            // TODO: 这行代码将数据加载到表“webdiskDataSet.userInfo”中。您可以根据需要移动或删除它。
            this.userInfoTableAdapter.Fill(this.webdiskDataSet.userInfo);
			//让窗体不闪烁
			//边展示边重绘控件
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
			FileInformation.Visible = false;

			AllFileSizeShow();



			TcpClient = new TcpClient();//创建监听对象
			try
			{
				TcpClient.Connect("192.168.160.2", Convert.ToInt32("5000"));//连接服务端（根据ip地址修改）
																			//TcpClient.Connect("192.168.1.4", Convert.ToInt32("5000"));//连接服务端（根据ip地址修改）
																			//TcpClient.Connect("134.175.15.205", Convert.ToInt32("5000"));//连接服务端（根据ip地址修改）

				if (Temp.Folder == false)//如果此用户没有用户文件夹
				{
					NetworkStream stream = TcpClient.GetStream();//发送数据到服务端，服务端创建用户文件夹
					byte[] bytrArray = Encoding.Unicode.GetBytes("|" + Temp.TmeploginName);
					stream.Write(bytrArray, 0, bytrArray.Length);
					Temp.Folder = true;

				}

			}
			catch (Exception ex)
			{
				//MessageBox.Show("连接失败" + ex.Message);
				return;
			}


			//重绘图片框
			System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
			path.AddEllipse(this.Hand.ClientRectangle);
			Region reg = new Region(path);
			this.Hand.Region = reg;




			//path.AddEllipse(this.Min.ClientRectangle);
			//this.Hand.Region = reg;


			AllFilePitch = true;
			label1.Text = Temp.TmeploginName;
			AllFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AllFile按下.png ");
			DFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\DFile初始.png ");
			PictureFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\PictureFile初始.png ");
			MusicFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\MusicFile初始.png ");
			VideoFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\VideoFile初始.png ");
			OtherFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\OtherFile初始.png ");
			Min.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\最小化初始.png ");
			Exit.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\关闭初始.png ");
			AddUser.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AddUser初始.png ");
			UserFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\UserFile初始.png ");

			SqlDataReader reader = null;

			if (Temp.Tempisadmin == "True")//管理员登录的时候
			{
				DBHelper.InitConnection();
				DBHelper.Conn.Close();
				DBHelper.Conn.Open();
				
				DataTable dt;
				dt = DBHelper.GetDataTable("select loginName 用户名,loginPass 用户密码,StartTime 注册时间 from userInfo");
				UserdataGridView.DataSource = dt;
				MyFilePic.Visible = true;
				UserPic.Visible = true;
				

			}
			else
			{//用户登录的时候
			 //this.BackgroundImage = Image.FromFile(ThePath + "\\..\\..\\pic\\主窗口1.png ");

				//ReviseButton.Visible = false;提交按钮
				MyFilePic.Visible = false;
				UserPic.Visible = false;
			}
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			DBHelper.Conn.Close();
			DBHelper.InitConnection();//连接数据库
									  //获取文件路径
			ColumnHeader ch = new ColumnHeader();
			ch.Text = "路径";
			//读取数据库

			reader = DBHelper.GetDataReader(string.Format("select * from Information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())//listView1存放文件的路径、listViewPic存放图标
			{
				int count = listView1.Items.Count;//获取路径ListView项的总和
				string FilePath = reader["FilePath"].ToString();
				string FileName = reader["FileName"].ToString();
				string FileExt = reader["FileExt"].ToString();
				listView1.Items.Add(FilePath);//将路径加入路径ListView
				if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 12;
				}
				else if (FileExt.ToLower() == "txt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 9;
				}
				else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 4;
				}
				else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 1;
				}
				else if (FileExt.ToLower() == "exe")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 5;
				}
				else if (FileExt.ToLower() == "torrent")                            //种子文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 14;
				}
				else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")    //网页文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 2;
				}
				else if (FileExt.ToLower() == "dll")                                //dll文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 0;
				}
				else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 7;
				}
				else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 13;
				}
				else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 15;
				}
				else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 8;
				}
				else
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 11;
				}
				//count++;
			}//listView1存放文件的路径、listViewPic存放图标
			reader.Close();
			DBHelper.Conn.Close();
		}
		private void Renovate()//刷新
		{
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			SqlDataReader reader = null;
			DBHelper.Conn.Close();
			DBHelper.InitConnection();//连接数据库
			reader = null;
			reader = DBHelper.GetDataReader(string.Format("select * from Information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())
			{
				int count = listView1.Items.Count;//获取路径ListView项的总和
				string FilePath = reader["FilePath"].ToString();
				string FileName = reader["FileName"].ToString();
				string FileExt = reader["FileExt"].ToString();
				listView1.Items.Add(FilePath);//将路径加入路径ListView
				if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 12;
				}
				else if (FileExt.ToLower() == "txt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 9;
				}
				else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 4;
				}
				else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 1;
				}
				else if (FileExt.ToLower() == "exe")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 5;
				}
				else if (FileExt.ToLower() == "torrent")                            //种子文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 14;
				}
				else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")    //网页文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 2;
				}
				else if (FileExt.ToLower() == "dll")                                //dll文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 0;
				}
				else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 7;
				}
				else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 13;
				}
				else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 15;
				}
				else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 8;
				}
				else
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 11;
				}
				//count++;
			}//listView1存放文件的路径、listViewPic存放图标
			reader.Close();
			DBHelper.Conn.Close();
		}

		private void Form1_MouseDown(object sender, MouseEventArgs e)//窗口鼠标按下
		{
			//FileInformation.Visible = false;
			mPoint = new Point(e.X, e.Y);//设置鼠标拖动

		}

		private void Form1_MouseMove(object sender, MouseEventArgs e)//窗口鼠标移动
		{
			if (e.Button == MouseButtons.Left)//设置鼠标拖动
			{
				this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
			}
		}

		private void AllFile_MouseDown(object sender, MouseEventArgs e)//全部文件鼠标按下
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(AllFile);
			AllFilePitch = true;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = false;
			AddUserPitch = false;
			UserFilePitch = false;
		}

		private void AllFile_MouseEnter(object sender, EventArgs e)//全部文件鼠标进入可见区域
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			AllFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AllFile经过.png ");
		}

		private void AllFile_MouseUp(object sender, MouseEventArgs e)//全部文件鼠标释放
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			AllFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AllFile按下.png ");
		}

		private void AllFile_MouseLeave(object sender, EventArgs e)//全部文件鼠标离开可见区域
		{
			LeaveType(AllFilePitch, AllFile);
		}

		private void DFile_MouseDown(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(DFile);
			AllFilePitch = false;
			DFilePitch = true;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = false;
			AddUserPitch = false;
			UserFilePitch = false;
		}//文档鼠标按下




		private void DFile_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			DFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\DFile经过.png ");
		}//文档鼠标进入可见范围

		private void DFile_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			DFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\DFile按下.png ");
		}//文档鼠标释放

		private void DFile_MouseLeave(object sender, EventArgs e)
		{
			LeaveType(DFilePitch, DFile);
		}//文档鼠标离开

		private void PictureFile_MouseDown(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(PictureFile);
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = true;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = false;
			AddUserPitch = false;
			UserFilePitch = false;
		}//图片鼠标按下

		private void PictureFile_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PictureFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\PictureFile经过.png ");
		}//图片鼠标进入可见范围

		private void PictureFile_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PictureFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\PictureFile按下.png ");
		}//图片鼠标释放

		private void PictureFile_MouseLeave(object sender, EventArgs e)
		{
			LeaveType(PictureFilePitch, PictureFile);
		}//图片鼠标离开

		private void MusicFile_MouseDown(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(MusicFile);
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = true;
			VideoFilePitch = false;
			OtherFilePitch = false;
			AddUserPitch = false;
			UserFilePitch = false;
		}//音乐鼠标按下

		private void MusicFile_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			MusicFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\MusicFile经过.png ");
		}//音乐鼠标进入可见范围

		private void MusicFile_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			MusicFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\MusicFile按下.png ");
		}//音乐鼠标释放

		private void MusicFile_MouseLeave(object sender, EventArgs e)
		{
			LeaveType(MusicFilePitch, MusicFile);
		}//音乐鼠标离开

		private void VideoFile_MouseDown(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(VideoFile);
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = true;
			OtherFilePitch = false;
			AddUserPitch = false;
			UserFilePitch = false;
		}//视频鼠标按下

		private void VideoFile_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			VideoFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\VideoFile经过.png ");
		}//视频鼠标进入

		private void VideoFile_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			VideoFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\VideoFile按下.png ");
		}//视频鼠标释放

		private void VideoFile_MouseLeave(object sender, EventArgs e)
		{
			LeaveType(VideoFilePitch, VideoFile);
		}//视频鼠标离开

		private void OtherFile_MouseDown(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(OtherFile);
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = true;
			AddUserPitch = false;
			UserFilePitch = false;
		}//其他文件鼠标按下

		private void OtherFile_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			OtherFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\OtherFile经过.png ");
		}//其他文件鼠标进入

		private void OtherFile_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			OtherFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\OtherFile按下.png ");
		}//其他文件鼠标释放

		private void OtherFile_MouseLeave(object sender, EventArgs e)
		{
			LeaveType(OtherFilePitch, OtherFile);

		}//其他文件鼠标离开

		private void Min_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Min.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\最小化按下.png ");
		}//最小化鼠标按下

		private void Min_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Min.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\最小化经过.png ");
		}//最小化鼠标进入可见范围

		private void Min_MouseLeave(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Min.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\最小化初始.png ");
		}//最小化鼠标离开

		private void Min_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Min.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\最小化经过.png ");
		}//最小化鼠标释放

		private void Exit_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Exit.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\关闭按下.png ");
		}//关闭鼠标按下

		private void Exit_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Exit.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\关闭经过.png ");
		}//关闭鼠标进入

		private void Exit_MouseLeave(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Exit.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\关闭初始.png ");
		}//关闭鼠标离开

		private void Exit_MouseMove(object sender, MouseEventArgs e)
		{

		}

		private void Exit_MouseUp(object sender, MouseEventArgs e)//关闭鼠标释放
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			Exit.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\关闭经过.png ");
		}

		private void Exit_Click(object sender, EventArgs e)
		{
            //this.Close();
            Application.Exit();
		}

		private void Min_Click(object sender, EventArgs e)
		{
			this.WindowState = FormWindowState.Minimized;//最小化
            IsMin = true;
		}


		private void AllFile_Click(object sender, EventArgs e)//单击全部文件
		{
			Renovate();
			listView1.Items.Clear();
			/*listView1.Items.Clear();
            listViewPic.Items.Clear();
            DBHelper.Conn.Close();
            DBHelper.InitConnection();//连接数据库
            //获取文件路径
            ColumnHeader ch = new ColumnHeader();
            ch.Text = "路径";
            //读取数据库
            SqlDataReader reader = null;
            reader = DBHelper.GetDataReader(string.Format("select * from Information where loginName='{0}'", Temp.TmeploginName));
            while (reader.Read())
            {
                int count = listView1.Items.Count;//获取路径ListView项的总和
                string FilePath = reader["FilePath"].ToString();
                string FileName = reader["FileName"].ToString();
                string FileExt = reader["FileExt"].ToString();
                listView1.Items.Add(FilePath);//将路径加入路径ListView
                if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 12;
                }
                else if (FileExt.ToLower() == "txt")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 9;
                }
                else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 4;
                }
                else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 1;
                }
                else if (FileExt.ToLower() == "exe")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 5;
                }
                else if (FileExt.ToLower() == "torrent")                            //种子文件
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 14;
                }
                else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")    //网页文件
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 2;
                }
                else if (FileExt.ToLower() == "dll")                                //dll文件
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 0;
                }
                else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 7;
                }
                else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 13;
                }
                else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 15;
                }
                else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 8;
                }
                else
                {
                    listViewPic.Items.Add(FileName);
                    listViewPic.Items[count].ImageIndex = 11;
                }
                //count++;
            }
            reader.Close();
            DBHelper.Conn.Close();*/
		}




		private void DFile_Click(object sender, EventArgs e)//单击文档
		{

			DBHelper.Conn.Close();
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			DBHelper.InitConnection();
			SqlDataReader reader = null;
			reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())
			{
				string FilePath = reader["FilePath"].ToString();
				string FileExt = reader["FileExt"].ToString();
				string FileName = reader["FileName"].ToString();
				if (FileExt.ToLower() == "doc" || FileExt.ToLower() == "docx" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf" || FileExt.ToLower() == "txt" || FileExt.ToLower() == "ppt" || FileExt.ToLower() == "pptx" || FileExt.ToLower() == "xls" || FileExt.ToLower() == "xlsx")
				{
					int count = listView1.Items.Count;//获取路径ListView项的总和
					listView1.Items.Add(FilePath);//将路径加入路径ListView
					if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
					{
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 12;
					}
					else if (FileExt.ToLower() == "txt")
					{
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 9;
					}
					else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
					{
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 4;
					}
					else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
					{
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 1;
					}
				}
			}
			reader.Close();
			DBHelper.Conn.Close();

		}

		private void PictureFile_Click(object sender, EventArgs e)//单击图片
		{
			DBHelper.Conn.Close();
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			DBHelper.InitConnection();
			SqlDataReader reader = null;
			reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())
			{
				string FilePath = reader["FilePath"].ToString();
				string FileExt = reader["FileExt"].ToString();
				string FileName = reader["FileName"].ToString();
				if (FileExt.ToLower() == "bmp" || FileExt.ToLower() == "jpg" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
				{
					int count = listView1.Items.Count;//获取路径ListView项的总和
					listView1.Items.Add(FilePath);//将路径加入路径ListView
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 8;
				}
			}
			reader.Close();
			DBHelper.Conn.Close();
		}

		private void MusicFile_Click(object sender, EventArgs e)//单击音乐
		{
			DBHelper.Conn.Close();
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			DBHelper.InitConnection();
			SqlDataReader reader = null;
			reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())
			{
				string FilePath = reader["FilePath"].ToString();
				string FileExt = reader["FileExt"].ToString();
				string FileName = reader["FileName"].ToString();
				if (FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape" || FileExt.ToLower() == "mp3")
				{
					int count = listView1.Items.Count;//获取路径ListView项的总和
					listView1.Items.Add(FilePath);//将路径加入路径ListView
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 13;
				}
			}
		}

		private void VideoFile_Click(object sender, EventArgs e)//单击视频
		{
			DBHelper.Conn.Close();
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			DBHelper.InitConnection();
			SqlDataReader reader = null;
			reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())
			{
				string FilePath = reader["FilePath"].ToString();
				string FileExt = reader["FileExt"].ToString();
				string FileName = reader["FileName"].ToString();
				if (FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "mp4" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
				{
					int count = listView1.Items.Count;//获取路径ListView项的总和
					listView1.Items.Add(FilePath);//将路径加入路径ListView
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 7;
				}
			}
		}

		private void OtherFile_Click(object sender, EventArgs e)//单击其他
		{
			DBHelper.Conn.Close();
			listView1.Items.Clear();
			listViewPic.Items.Clear();
			DBHelper.InitConnection();
			SqlDataReader reader = null;
			reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
			while (reader.Read())
			{
				string FilePath = reader["FilePath"].ToString();
				string FileExt = reader["FileExt"].ToString();
				string FileName = reader["FileName"].ToString();
				if (FileExt.ToLower() == "rar" || FileExt.ToLower() == "zip" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso" || FileExt.ToLower() == "html" || FileExt.ToLower() == "htm" || FileExt.ToLower() == "torrent")
				{
					if (FileExt.ToLower() == "rar" || FileExt.ToLower() == "zip" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 15;
					}
					else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 2;
					}
					else
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 14;
					}
				}
			}
		}

		private void listView1_DragEnter(object sender, DragEventArgs e)
		{

		}

		private void UserHome_MouseLeave(object sender, EventArgs e)
		{

		}

		private void listViewPic_DragEnter(object sender, DragEventArgs e)//拖放文件到控件工作区域
		{
			e.Effect = DragDropEffects.Copy;//设置拖放
		}

		private void listViewPic_DoubleClick(object sender, EventArgs e)//双击listwiew项的时候
		{
			try
			{

				string choose = this.listView1.Items[listViewPic.SelectedItems[0].Index].Text;//获取另一个ListView的索引，通过索引获取路径
				Process pr = new Process();
				pr.StartInfo.FileName = choose;
				//MessageBox.Show(choose);
				pr.Start();//执行路径



			}
			catch
			{

				string a = listViewPic.Items[listViewPic.SelectedItems[0].Index].ToString();
				DownloadFileName = a.Replace("ListViewItem: {", "");
				DownloadFileName = DownloadFileName.Substring(0, DownloadFileName.Length - 1);


				save.FilterIndex = 1;
				save.RestoreDirectory = true;
				save.FileName = DownloadFileName;
				if (save.ShowDialog() == DialogResult.OK)
				{
					DownloadBack.RunWorkerAsync();
				}

				DBHelper.InitConnection();
				//DBHelper.ExecuteNonQuery(string.Format("insert into information(FilePath,FileName,FileExt,FileSize,STime,loginName)values('{0}','{1}','{2}','{3}',GETDATE(),'{4}')", save.FileName, FileName, FileExt, FileSize, Temp.TmeploginName));


				DBHelper.ExecuteNonQuery(string.Format("update information set FilePath='{0}' where FileName='{1}'", save.FileName, DownloadFileName));
				Renovate();
				return;
			}
		}

		private void GetFile(string str)//得到文件
		{
			bool FileSame = false;//相同文件
			LoadPic.Visible = true;

			DBHelper.InitConnection();
			listView1.Items.Add(str);//将路径加入路径ListView
			int count = listView1.Items.Count;//获取路径ListView项的总和
			for (int i = str.Length - 1; i >= 0; i--)
			{
				if (str.Substring(i, 1) == ".")
				{
					FileExt = str.Substring(i + 1);
					break;
				}
			}
			//获取文件大小
			FileInfo fileInfo = new FileInfo(str);//获取文件大小
			double FileSize = fileInfo.Length;
			//加入数据
			for (int i = str.Length - 1; i >= 0; i--)//截取文件名
			{
				if (str.Substring(i, 1) == "\\")
				{
					FileName = str.Substring(i + 1);
					break;
				}
			}


			SqlDataReader reader = DBHelper.GetDataReader(string.Format("select * from Information where loginName='{0}'", Temp.TmeploginName));

			while (reader.Read())
			{
				string FileName = reader["FileName"].ToString();
				if (this.FileName == FileName)
				{
					MessageBox.Show("已有此文件");
					FileSame = true;
				}

			}
			reader.Close();

			if (FileSame == false)
			{
				DBHelper.ExecuteNonQuery(string.Format("insert into information(FilePath,FileName,FileExt,FileSize,STime,loginName)values('{0}','{1}','{2}','{3}',GETDATE(),'{4}')", this.listView1.Items[count - 1].Text, FileName, FileExt, FileSize, Temp.TmeploginName));

				if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 12;
				}
				else if (FileExt.ToLower() == "txt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 9;
				}
				else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 4;
				}
				else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 1;
				}
				else if (FileExt.ToLower() == "exe")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 5;
				}
				else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 7;
				}
				else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 13;
				}
				else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 15;
				}
				else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 8;
				}
				else if (FileExt.ToLower() == "torrent")//种子文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 14;
				}
				else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")//网页文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 2;
				}
				else if (FileExt.ToLower() == "dll")                            //dll文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 0;
				}
				else
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count - 1].ImageIndex = 11;
				}


				fs = new FileStream(str, FileMode.Open, FileAccess.Read);//转成文件流


				backgroundWorker1.RunWorkerAsync();

			}





		}


		private void listViewPic_DragDrop(object sender, DragEventArgs e)//得到文件的时候
		{
			string str = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//提取文件路径

			GetFile(str);
		}

		private void UserdataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)//管理用户dataGridView的内容发生改变的时候
		{
			//获取修改位置的横坐标和纵坐标
			int columnIndex = e.ColumnIndex;
			int rowindex = e.RowIndex;
			if (columnIndex >= 0 && rowindex >= 0)
			{
				str = UserdataGridView.Rows[rowindex].Cells[columnIndex].Value.ToString();//得到修改内容
				frist = UserdataGridView.Rows[rowindex].Cells[0].Value.ToString();//得到修改的第一列
				name = UserdataGridView.Columns[e.ColumnIndex].HeaderText;//获取修改的字段
			}
		}

		private void UserdataGridView_Click(object sender, EventArgs e)//单击管理用户dataGridView的内容
		{
			int index = UserdataGridView.CurrentRow.Index;//得到单击位置
			userId = UserdataGridView.Rows[index].Cells[0].Value.ToString();
		}

		private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)//用户打开
		{
			int index;
			try
			{
				index = listViewPic.SelectedItems[0].Index;//获取listViewPic选中的坐标
			}
			catch
			{
				return;
			}
			if (index < 0)
			{
				return;
			}
			else
			{
				string choose = this.listView1.Items[index].Text;//获取另一个ListView的索引，通过索引获取路径
				Process pr = new Process();
				pr.StartInfo.FileName = choose;
				pr.Start();//执行路径
			}
		}

		private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)//删除
		{
			try
			{
				DialogResult result;
				result = MessageBox.Show("确认删除此文件？", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
				if (result == DialogResult.OK)
				{
					NetworkStream stream = TcpClient.GetStream();
					byte[] byteArray = new byte[1024];


					string a = listViewPic.Items[listViewPic.SelectedItems[0].Index].ToString();
					DownloadFileName = a.Replace("ListViewItem: {", "");
					DownloadFileName = DownloadFileName.Substring(0, DownloadFileName.Length - 1);

					byte[] bytrArray = Encoding.Unicode.GetBytes("*" + Temp.TmeploginName + "\\" + DownloadFileName);//将要发送的数据转化成为一个字节数组
					Thread.Sleep(10);
					stream.Write(bytrArray, 0, bytrArray.Length);//发送文件长度

					int index;
					try
					{
						index = listViewPic.SelectedItems[0].Index;//获取listViewPic选中的坐标
					}
					catch
					{
						return;
					}
					if (index < 0)
					{
						return;
					}
					else
					{
						string choose = this.listView1.Items[index].Text;//获取另一个ListView的索引，通过索引获取路径
						DBHelper.InitConnection();
						DBHelper.ExecuteNonQuery(string.Format("delete from Information where FilePath='{0}'", choose));
						if (DFilePitch == true)//文档
						{
							DBHelper.Conn.Close();
							listView1.Items.Clear();
							listViewPic.Items.Clear();
							DBHelper.InitConnection();
							SqlDataReader reader = null;
							reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
							while (reader.Read())
							{
								string FilePath = reader["FilePath"].ToString();
								string FileExt = reader["FileExt"].ToString();
								string FileName = reader["FileName"].ToString();
								if (FileExt.ToLower() == "doc" || FileExt.ToLower() == "docx" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf" || FileExt.ToLower() == "txt" || FileExt.ToLower() == "ppt" || FileExt.ToLower() == "pptx" || FileExt.ToLower() == "xls" || FileExt.ToLower() == "xlsx")
								{
									int count = listView1.Items.Count;//获取路径ListView项的总和
									listView1.Items.Add(FilePath);//将路径加入路径ListView
									if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
									{
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 12;
									}
									else if (FileExt.ToLower() == "txt")
									{
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 9;
									}
									else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
									{
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 4;
									}
									else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
									{
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 1;
									}
								}
							}
							reader.Close();
							DBHelper.Conn.Close();
						}

						if (PictureFilePitch == true)//图片
						{
							DBHelper.Conn.Close();
							listView1.Items.Clear();
							listViewPic.Items.Clear();
							DBHelper.InitConnection();
							SqlDataReader reader = null;
							reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
							while (reader.Read())
							{
								string FilePath = reader["FilePath"].ToString();
								string FileExt = reader["FileExt"].ToString();
								string FileName = reader["FileName"].ToString();
								if (FileExt.ToLower() == "bmp" || FileExt.ToLower() == "jpg" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
								{
									int count = listView1.Items.Count;//获取路径ListView项的总和
									listView1.Items.Add(FilePath);//将路径加入路径ListView
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 8;
								}
							}
							reader.Close();
							DBHelper.Conn.Close();
						}
						if (MusicFilePitch == true)//音乐
						{
							DBHelper.Conn.Close();
							listView1.Items.Clear();
							listViewPic.Items.Clear();
							DBHelper.InitConnection();
							SqlDataReader reader = null;
							reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
							while (reader.Read())
							{
								string FilePath = reader["FilePath"].ToString();
								string FileExt = reader["FileExt"].ToString();
								string FileName = reader["FileName"].ToString();
								if (FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape" || FileExt.ToLower() == "mp3")
								{
									int count = listView1.Items.Count;//获取路径ListView项的总和
									listView1.Items.Add(FilePath);//将路径加入路径ListView
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 13;
								}
							}
							reader.Close();
							DBHelper.Conn.Close();
						}
						if (VideoFilePitch == true)//视频
						{
							DBHelper.Conn.Close();
							listView1.Items.Clear();
							listViewPic.Items.Clear();
							DBHelper.InitConnection();
							SqlDataReader reader = null;
							reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
							while (reader.Read())
							{
								string FilePath = reader["FilePath"].ToString();
								string FileExt = reader["FileExt"].ToString();
								string FileName = reader["FileName"].ToString();
								if (FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "mp4" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
								{
									int count = listView1.Items.Count;//获取路径ListView项的总和
									listView1.Items.Add(FilePath);//将路径加入路径ListView
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 7;
								}
							}
							reader.Close();
							DBHelper.Conn.Close();
						}
						if (OtherFilePitch == true)//其他
						{
							DBHelper.Conn.Close();
							listView1.Items.Clear();
							listViewPic.Items.Clear();
							DBHelper.InitConnection();
							SqlDataReader reader = null;
							reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
							while (reader.Read())
							{
								string FilePath = reader["FilePath"].ToString();
								string FileExt = reader["FileExt"].ToString();
								string FileName = reader["FileName"].ToString();
								if (FileExt.ToLower() == "rar" || FileExt.ToLower() == "zip" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso" || FileExt.ToLower() == "html" || FileExt.ToLower() == "htm" || FileExt.ToLower() == "torrent")
								{
									if (FileExt.ToLower() == "rar" || FileExt.ToLower() == "zip" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
									{
										int count = listView1.Items.Count;//获取路径ListView项的总和
										listView1.Items.Add(FilePath);//将路径加入路径ListView
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 15;
									}
									else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")
									{
										int count = listView1.Items.Count;//获取路径ListView项的总和
										listView1.Items.Add(FilePath);//将路径加入路径ListView
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 2;
									}
									else
									{
										int count = listView1.Items.Count;//获取路径ListView项的总和
										listView1.Items.Add(FilePath);//将路径加入路径ListView
										listViewPic.Items.Add(FileName);
										listViewPic.Items[count].ImageIndex = 14;
									}
								}
							}
							reader.Close();
							DBHelper.Conn.Close();
						}
						if (AllFilePitch == true)
						{
							listView1.Items.Clear();
							listViewPic.Items.Clear();
							SqlDataReader reader = null;
							DBHelper.Conn.Close();
							DBHelper.InitConnection();//连接数据库
							reader = null;
							reader = DBHelper.GetDataReader(string.Format("select * from Information where loginName='{0}'", Temp.TmeploginName));
							while (reader.Read())
							{
								int count = listView1.Items.Count;//获取路径ListView项的总和
								string FilePath = reader["FilePath"].ToString();
								string FileName = reader["FileName"].ToString();
								string FileExt = reader["FileExt"].ToString();
								listView1.Items.Add(FilePath);//将路径加入路径ListView
								if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 12;
								}
								else if (FileExt.ToLower() == "txt")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 9;
								}
								else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 4;
								}
								else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 1;
								}
								else if (FileExt.ToLower() == "exe")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 5;
								}
								else if (FileExt.ToLower() == "torrent")                            //种子文件
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 14;
								}
								else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")    //网页文件
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 2;
								}
								else if (FileExt.ToLower() == "dll")                                //dll文件
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 0;
								}
								else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 7;
								}
								else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 13;
								}
								else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 15;
								}
								else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 8;
								}
								else
								{
									listViewPic.Items.Add(FileName);
									listViewPic.Items[count].ImageIndex = 11;
								}
								//count++;
							}
							reader.Close();
							DBHelper.Conn.Close();
						}
					}
				}
				else
				{
					MessageBox.Show("取消删除", "温馨提示");
				}
				AllFileSizeShow();

			}
			catch
			{
				return;
			}





		}//用户删除

		private void toolStripMenuItem1_Click(object sender, EventArgs e)//管理员打开
		{
			Temp.Name = TX_Name.Text;
			manage manage = new manage();
            manage.ShowDialog();
			
		}

		private void toolStripMenuItem2_Click(object sender, EventArgs e)//删除用户
		{
			DialogResult result;
			result = MessageBox.Show("确认删除此用户？", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
			if (result == DialogResult.OK)
			{
				DBHelper.InitConnection();
				bool a = DBHelper.ExecuteNonQuery(string.Format("delete userInfo where userId='{0}'", this.userId));
				if (a == true)
				{
					MessageBox.Show("删除成功", "提示");
					DBHelper.InitConnection();
					DBHelper.Conn.Close();
					DBHelper.Conn.Open();
					SqlDataReader reader = DBHelper.GetDataReader("select * from userInfo");
					//清空内容
					UserdataGridView.Rows.Clear();
					//重新载入
					while (reader.Read())
					{
						string userId = reader["userId"].ToString();
						string loginName = reader["loginName"].ToString();
						string loginPass = reader["loginPass"].ToString();
						string StartTime = reader["StartTime"].ToString();
						string EndTime = reader["EndTime"].ToString();
						string isadmin = reader["isadmin"].ToString();
						UserdataGridView.Rows.Add(userId, loginName, loginPass, StartTime, EndTime, isadmin);
					}
					DBHelper.Conn.Close();
					reader.Close();
				}
			}
			else
			{
				MessageBox.Show("删除失败！", "提示");
			}
		}//管理者删户

		private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)//管理者刷新
		{
			DBHelper.Conn.Close();
			DBHelper.Conn.Open();
			SqlDataReader reader = DBHelper.GetDataReader("select * from userInfo");
			//UserdataGridView.Rows.Clear();
			//while (reader.Read())
			//{
			//	string userId = reader["userId"].ToString();
			//	string loginName = reader["loginName"].ToString();
			//	string loginPass = reader["loginPass"].ToString();
			//	string StartTime = reader["StartTime"].ToString();
			//	string EndTime = reader["EndTime"].ToString();
			//	string isadmin = reader["isadmin"].ToString();
			//	UserdataGridView.Rows.Add(userId, loginName, loginPass, StartTime, EndTime, isadmin);
			//}
			DBHelper.Conn.Close();
			DataTable dt;
			dt = DBHelper.GetDataTable("select userId 用户ID,loginName 用户名,loginPass 用户密码,StartTime 注册时间,isadmin 是否为管理员 from userInfo");
			UserdataGridView.DataSource = dt;
			DBHelper.Conn.Close();
			reader.Close();

		}

		private void KidRenovate()
		{
			if (AllFilePitch == true)
			{
				Renovate();

			}

			if (DFilePitch == true)//文档
			{
				DBHelper.Conn.Close();
				listView1.Items.Clear();
				listViewPic.Items.Clear();
				DBHelper.InitConnection();
				SqlDataReader reader = null;
				reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
				while (reader.Read())
				{
					string FilePath = reader["FilePath"].ToString();
					string FileExt = reader["FileExt"].ToString();
					string FileName = reader["FileName"].ToString();
					if (FileExt.ToLower() == "doc" || FileExt.ToLower() == "docx" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf" || FileExt.ToLower() == "txt" || FileExt.ToLower() == "ppt" || FileExt.ToLower() == "pptx" || FileExt.ToLower() == "xls" || FileExt.ToLower() == "xlsx")
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
						{
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 12;
						}
						else if (FileExt.ToLower() == "txt")
						{
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 9;
						}
						else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
						{
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 4;
						}
						else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
						{
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 1;
						}
					}
				}
				reader.Close();
				DBHelper.Conn.Close();
			}
			if (PictureFilePitch == true)//图片
			{
				DBHelper.Conn.Close();
				listView1.Items.Clear();
				listViewPic.Items.Clear();
				DBHelper.InitConnection();
				SqlDataReader reader = null;
				reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
				while (reader.Read())
				{
					string FilePath = reader["FilePath"].ToString();
					string FileExt = reader["FileExt"].ToString();
					string FileName = reader["FileName"].ToString();
					if (FileExt.ToLower() == "bmp" || FileExt.ToLower() == "jpg" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 8;
					}
				}
				reader.Close();
				DBHelper.Conn.Close();
			}
			if (MusicFilePitch == true)//音乐
			{
				DBHelper.Conn.Close();
				listView1.Items.Clear();
				listViewPic.Items.Clear();
				DBHelper.InitConnection();
				SqlDataReader reader = null;
				reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
				while (reader.Read())
				{
					string FilePath = reader["FilePath"].ToString();
					string FileExt = reader["FileExt"].ToString();
					string FileName = reader["FileName"].ToString();
					if (FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape" || FileExt.ToLower() == "mp3")
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 13;
					}
				}
				reader.Close();
				DBHelper.Conn.Close();
			}
			if (VideoFilePitch == true)//视频
			{
				DBHelper.Conn.Close();
				listView1.Items.Clear();
				listViewPic.Items.Clear();
				DBHelper.InitConnection();
				SqlDataReader reader = null;
				reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
				while (reader.Read())
				{
					string FilePath = reader["FilePath"].ToString();
					string FileExt = reader["FileExt"].ToString();
					string FileName = reader["FileName"].ToString();
					if (FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "mp4" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
					{
						int count = listView1.Items.Count;//获取路径ListView项的总和
						listView1.Items.Add(FilePath);//将路径加入路径ListView
						listViewPic.Items.Add(FileName);
						listViewPic.Items[count].ImageIndex = 7;
					}
				}
				reader.Close();
				DBHelper.Conn.Close();
			}
			if (OtherFilePitch == true)//其他
			{
				DBHelper.Conn.Close();
				listView1.Items.Clear();
				listViewPic.Items.Clear();
				DBHelper.InitConnection();
				SqlDataReader reader = null;
				reader = DBHelper.GetDataReader(string.Format("select * from information where loginName='{0}'", Temp.TmeploginName));
				while (reader.Read())
				{
					string FilePath = reader["FilePath"].ToString();
					string FileExt = reader["FileExt"].ToString();
					string FileName = reader["FileName"].ToString();
					if (FileExt.ToLower() == "rar" || FileExt.ToLower() == "zip" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso" || FileExt.ToLower() == "html" || FileExt.ToLower() == "htm" || FileExt.ToLower() == "torrent")
					{
						if (FileExt.ToLower() == "rar" || FileExt.ToLower() == "zip" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
						{
							int count = listView1.Items.Count;//获取路径ListView项的总和
							listView1.Items.Add(FilePath);//将路径加入路径ListView
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 15;
						}
						else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")
						{
							int count = listView1.Items.Count;//获取路径ListView项的总和
							listView1.Items.Add(FilePath);//将路径加入路径ListView
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 2;
						}
						else
						{
							int count = listView1.Items.Count;//获取路径ListView项的总和
							listView1.Items.Add(FilePath);//将路径加入路径ListView
							listViewPic.Items.Add(FileName);
							listViewPic.Items[count].ImageIndex = 14;
						}
					}
				}
				reader.Close();
				DBHelper.Conn.Close();
			}


		}



		private void 刷新ToolStripMenuItem1_Click(object sender, EventArgs e)//用户刷新
		{

			//listView1.Items.Clear();
			//listViewPic.Items.Clear();
			KidRenovate();


		}

		private void MyFile_Click(object sender, EventArgs e)
		{
			//Filepanel.Visible = true;
			UserPanel.Visible = false;
			listViewPic.Visible = true;
			UserdataGridView.Visible = false;
		}//管理员单击我的文件

		private void UserSupervise_Click(object sender, EventArgs e)
		{
			UserPanel.Visible = true;
			listViewPic.Visible = false;
			UserdataGridView.Visible = true;
		}//管理员单击用户管理

		private void insertUser_Click(object sender, EventArgs e)
		{

		}

		private void SignOut_Click(object sender, EventArgs e)
		{
			log_on_Form LO = new log_on_Form();
			LO.Show();
			this.Close();
		}
		private void UserHome_FormClosing(object sender, FormClosingEventArgs e)
		{
			Type.AnimateWindow(this.Handle, 300, Type.AW_BLEND | Type.AW_HIDE);//设置窗口淡出
			NetworkStream stream = TcpClient.GetStream();//发送数据到服务端，关闭
			byte[] bytrArray = Encoding.Unicode.GetBytes("END");
			stream.Write(bytrArray, 0, bytrArray.Length);
		}

		private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
		{

			byte[] infbytes = new byte[fs.Length];//
			NetworkStream stream = TcpClient.GetStream();

			byte[] bytrArray = Encoding.Unicode.GetBytes(fs.Length + "<" + FileName + "<" + Temp.TmeploginName);//将要发送的数据转化成为一个字节数组
																												//发送文件大小<文件名<用户名，服务端将文件写入到相应的用户文件夹
			Thread.Sleep(10);
			stream.Write(bytrArray, 0, bytrArray.Length);//发送以上文件信息

			byte[] section = new byte[256];//分段发送文件，每次发256字节
			int sum = 0;
			TransferPro.Maximum = infbytes.Length / 256 + 1;
			for (int num = 0; num <= infbytes.Length / 256 + 1; num++)
			{
				for (int j = 0; sum < infbytes.Length; sum++, j++)
				{
					if (j == 256)
					{
						j = 0;
						break;
					}
					section[j] = infbytes[sum];
				}
				TransferPro.Value = num;
				fs.Read(section, 0, section.Length);
				stream.Write(section, 0, section.Length);//发送字节流*/
			}
			Thread.Sleep(10);

			TransferPro.Value = 0;

			LoadPic.Visible = false;
            if (IsMin == true)
            {
                PalletIcon.ShowBalloonTip(1000, "文件上传完毕", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.None);
            }
            IsMin = false;
                


            //PalletIcon.ShowBalloonTip(1000, "文件上传完毕", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.Info);
            AllFileSizeShow();
		}

		private void SignOut_MouseEnter(object sender, EventArgs e)
		{
			SignOut.ForeColor = Color.LightGray;
		}

		private void SignOut_MouseLeave(object sender, EventArgs e)
		{
			SignOut.ForeColor = Color.White;

		}

		private void SignOut_MouseUp(object sender, MouseEventArgs e)
		{
			SignOut.ForeColor = Color.LightGray;

		}

		private void SignOut_MouseDown(object sender, MouseEventArgs e)
		{
			SignOut.ForeColor = Color.Gray;

		}

		private void AddUser_MouseDown(object sender, MouseEventArgs e)//添加用户
		{
			//string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			//AddUser.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\添加用户按下.png ");



			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(AddUser);
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = false;
			AddUserPitch = true;
			UserFilePitch = false;
		}

		private void AddUser_Click(object sender, EventArgs e)
		{
			Insert inser = new Insert();
			inser.Show();
		}

		private void AddUser_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			AddUser.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AddUser经过.png ");
		}

		private void AddUser_MouseLeave(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			AddUser.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AddUser初始.png ");
		}

		private void AddUser_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			AddUser.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\AddUser经过.png ");
		}

		private void UserFile_MouseDown(object sender, MouseEventArgs e)//用户文件
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			PressDown(UserFile);
			AllFilePitch = false;
			DFilePitch = false;
			PictureFilePitch = false;
			MusicFilePitch = false;
			VideoFilePitch = false;
			OtherFilePitch = false;
			AddUserPitch = false;
			UserFilePitch = true;
		}

		private void UserFile_MouseEnter(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			UserFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\UserFile经过.png ");
		}

		private void UserFile_MouseLeave(object sender, EventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			UserFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\UserFile初始.png ");
		}

		private void UserFile_MouseUp(object sender, MouseEventArgs e)
		{
			string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			UserFile.Image = Image.FromFile(ThePath + "\\..\\..\\pic\\UserFile经过.png ");
		}

		private void fileSupervise_Click(object sender, EventArgs e)
		{

		}

		private void Hand_Click(object sender, EventArgs e)
		{
			Information information = new Information();
			information.Show();
		}


		string DownloadFileName;
		private void Download(string FilePath)//下载文件
		{
			NetworkStream stream = TcpClient.GetStream();
			byte[] byteArray = new byte[1024];
			while (true)
			{
				string[] str = DownloadFileName.Split('\\');
				//MessageBox.Show(Temp.TmeploginName+"\\"+ str[str.Length - 1]);
				byte[] bytrArray = Encoding.Unicode.GetBytes(">" + Temp.TmeploginName + "\\" + str[str.Length - 1]);//将要发送的数据转化成为一个字节数组
				Thread.Sleep(10);
				stream.Write(bytrArray, 0, bytrArray.Length);//发送文件长度

				int length = stream.Read(byteArray, 0, byteArray.Length);//将流里的字节数组放到bayArray里边   
				string receFileLen = Encoding.Unicode.GetString(byteArray, 0, length);
				//MessageBox.Show(receFileLen);
				int a = int.Parse(receFileLen.Substring(0, receFileLen.Length - 1));

				TransferPro.Maximum = a / 256 + 1;
				LoadPic.Visible = true;
				byte[] section = new byte[256];
				int i = 0;
				byte[] bits = new byte[a];
				for (int num = 0; num <= a / 256 + 1; num++)
				{
					stream.Read(section, 0, section.Length);
					for (int j = 0; i < a; j++, i++)
					{
						if (j == 256)
						{
							j = 0;
							break;
						}
						bits[i] = section[j];
					}
					TransferPro.Value = num;
				}
				MemoryStream ms = new MemoryStream(bits);
				//MessageBox.Show(FilePath);
				File.WriteAllBytes(FilePath, bits);
				TransferPro.Maximum = 0;
				LoadPic.Visible = false;
				Array.Clear(byteArray, 0, byteArray.Length);
                if (IsMin == true)
                {
                    PalletIcon.ShowBalloonTip(1000, "文件下载完毕", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.None);
                }
                IsMin = false;
                break;
			}


		}
		SaveFileDialog save = new SaveFileDialog();
		FolderBrowserDialog FD = new FolderBrowserDialog();

		private void 下载ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				string a = listViewPic.Items[listViewPic.SelectedItems[0].Index].ToString();
				DownloadFileName = a.Replace("ListViewItem: {", "");
				DownloadFileName = DownloadFileName.Substring(0, DownloadFileName.Length - 1);
				if (FD.ShowDialog() == DialogResult.OK)
				{
					DBHelper.InitConnection();
					DBHelper.ExecuteNonQuery(string.Format("update Information set FilePath='{0}' where FileName='{1}'", FD.SelectedPath + "\\" + DownloadFileName, DownloadFileName));
					DownloadBack.RunWorkerAsync();
					Renovate();
				}
			}
			catch
			{
				return;
			}
		}

		private void DownloadBack_DoWork(object sender, DoWorkEventArgs e)
		{
			Download(FD.SelectedPath + "\\" + DownloadFileName);
		}

		private void 属性ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				string a = listViewPic.Items[listViewPic.SelectedItems[0].Index].ToString();
				DownloadFileName = a.Replace("ListViewItem: {", "");
				DownloadFileName = DownloadFileName.Substring(0, DownloadFileName.Length - 1);
				Temp.FileName = DownloadFileName;
				DBHelper.Conn.Close();
				SqlDataReader reader = DBHelper.GetDataReader(string.Format("select * from Information where FileName='{0}'", Temp.FileName));
				if (reader.Read())
				{
					FileNameTex.Text = reader["FileName"].ToString();
					string FileExt = reader["FileExt"].ToString();
					FileExtlab.Text = FileExt;
					Size.Text = (double.Parse(reader["FileSize"].ToString()) / 1024.0 / 1024.0).ToString("0.00") + "MB";
					Time.Text = reader["Stime"].ToString();

					if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
					{
						Icon.Image = imageList1.Images[12];
					}
					else if (FileExt.ToLower() == "txt")
					{
						Icon.Image = imageList1.Images[9];
					}
					else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc")
					{
						Icon.Image = imageList1.Images[4];
					}
					else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
					{
						Icon.Image = imageList1.Images[1];
					}
					else if (FileExt.ToLower() == "exe")
					{
						Icon.Image = imageList1.Images[5];
					}
					else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
					{
						Icon.Image = imageList1.Images[7];
					}
					else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
					{
						Icon.Image = imageList1.Images[13];
					}
					else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
					{
						Icon.Image = imageList1.Images[15];
					}
					else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
					{
						Icon.Image = imageList1.Images[8];
					}
					else if (FileExt.ToLower() == "torrent")//种子文件
					{
						Icon.Image = imageList1.Images[14];
					}
					else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")//网页文件
					{
						Icon.Image = imageList1.Images[2];
					}
					else if (FileExt.ToLower() == "dll")                            //dll文件
					{
						Icon.Image = imageList1.Images[0];
					}
					else
					{
						Icon.Image = imageList1.Images[11];
					}


				}
				FileInformation.Visible = true;
				reader.Close();
				DBHelper.Conn.Close();
			}
			catch
			{

				return;
			}
		}

		private void label3_Click(object sender, EventArgs e)
		{

		}

		private void UploadPic_MouseDown(object sender, MouseEventArgs e)//按下
		{
			FileInformation.Visible = false;
			UploadPic.Image = Image.FromFile("Pic\\上传按下.png");
		}

		private void UploadPic_MouseEnter(object sender, EventArgs e)//进入
		{
			UploadPic.Image = Image.FromFile("Pic\\上传经过.png");

		}

		private void UploadPic_MouseLeave(object sender, EventArgs e)//离开
		{
			UploadPic.Image = Image.FromFile("Pic\\上传初始.png");

		}

		private void UploadPic_MouseUp(object sender, MouseEventArgs e)//释放
		{
			UploadPic.Image = Image.FromFile("Pic\\上传经过.png");

		}

		private void DownloadPic_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;
			DownloadPic.Image = Image.FromFile("Pic\\下载按下.png");
		}

		private void DownloadPic_MouseEnter(object sender, EventArgs e)
		{
			DownloadPic.Image = Image.FromFile("Pic\\下载经过.png");

		}

		private void DownloadPic_MouseLeave(object sender, EventArgs e)
		{
			DownloadPic.Image = Image.FromFile("Pic\\下载初始.png");

		}

		private void DownloadPic_MouseUp(object sender, MouseEventArgs e)
		{
			DownloadPic.Image = Image.FromFile("Pic\\下载经过.png");

		}

		private void MyFilePic_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;
			MyFilePic.Image = Image.FromFile("Pic\\我的文件初始.png");
		}

		private void MyFilePic_MouseEnter(object sender, EventArgs e)
		{
			MyFilePic.Image = Image.FromFile("Pic\\我的文件经过.png");

		}

		private void MyFilePic_MouseLeave(object sender, EventArgs e)
		{
			MyFilePic.Image = Image.FromFile("Pic\\我的文件初始.png");

		}

		private void MyFilePic_MouseUp(object sender, MouseEventArgs e)
		{
			MyFilePic.Image = Image.FromFile("Pic\\我的文件经过.png");

		}

		private void UserPic_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;
			UserPic.Image = Image.FromFile("Pic\\用户管理按下.png");
		}

		private void UserPic_MouseHover(object sender, EventArgs e)
		{

		}

		private void UserPic_MouseEnter(object sender, EventArgs e)
		{
			UserPic.Image = Image.FromFile("Pic\\用户管理经过.png");

		}

		private void UserPic_MouseLeave(object sender, EventArgs e)
		{
			UserPic.Image = Image.FromFile("Pic\\用户管理初始.png");

		}

		private void UserPic_MouseUp(object sender, MouseEventArgs e)
		{
			UserPic.Image = Image.FromFile("Pic\\用户管理经过.png");

		}

		private void MyFilePic_Click(object sender, EventArgs e)
		{
			panel2.Visible = false;
			FilePanel.Visible = true;
			UserPanel.Visible = false;
			UserdataGridView.Visible = false;
			TransferPro.Visible = true;
			listViewPic.Visible = true;
			Submit.Visible = false;
			FileInformation.Visible = false;

		}

		private void UserPic_Click(object sender, EventArgs e)
		{
			panel2.Visible = true;
			FilePanel.Visible = false;
			UserPanel.Visible = true;
			UserdataGridView.Visible = true;
			listViewPic.Visible = false;
			Submit.Visible = true;
			TransferPro.Visible = false;
			FileInformation.Visible = false;


		}

		private void UploadPic_Click(object sender, EventArgs e)
		{
			if (openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				GetFile(openFileDialog1.FileName);
            }
			FileInformation.Visible = false;
		}

		private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
		{

		}

		private void listViewPic_ItemActivate(object sender, EventArgs e)
		{

		}

		private void DownloadPic_Click(object sender, EventArgs e)
		{
			FileInformation.Visible = false;

			try
			{
				string a = listViewPic.Items[listViewPic.SelectedItems[0].Index].ToString();
				DownloadFileName = a.Replace("ListViewItem: {", "");
				DownloadFileName = DownloadFileName.Substring(0, DownloadFileName.Length - 1);
				if (FD.ShowDialog() == DialogResult.OK)
				{
					DBHelper.InitConnection();
					DBHelper.ExecuteNonQuery(string.Format("update Information set FilePath='{0}' where FileName='{1}'", FD.SelectedPath + "\\" + DownloadFileName, DownloadFileName));
					DownloadBack.RunWorkerAsync();
					Renovate();
				}
			}
			catch
			{

				return;
			}




		}

		private void Submit_Click(object sender, EventArgs e)
		{
			DBHelper.Conn.Close();
			string admin = "";
			if (radioButton2.Checked)
			{
				admin = "false";
			}
			else
			{
				admin = "true";
			}
			DBHelper.InitConnection();
			bool a= DBHelper.ExecuteNonQuery(string.Format("update userInfo set loginName='{0}',loginPass='{1}',isadmin='{2}' where userId='{3}'", TX_Name.Text, TX_Pass.Text, admin,UserID));
			if (a==true)
			{
				MessageBox.Show("修改成功", "提示");
				string sql = string.Format("select userId 用户ID,loginName 用户名,loginPass 用户密码,StartTime 注册时间,isadmin 是否为管理员 from userInfo");
				UserdataGridView.DataSource = DBHelper.GetDataSet(sql).Tables[0];
			}
			else
			{
				MessageBox.Show("修改失败", "提示");
			}
			
		}

		private void FileNameTex_Click(object sender, EventArgs e)
		{
			FileNameTex.ReadOnly = false;
		}

		private void panel2_Click(object sender, EventArgs e)
		{
			FileNameTex.ReadOnly = true;
		}

		private void SaveMessage_Click(object sender, EventArgs e)
		{
			DBHelper.ExecuteNonQuery(string.Format("update Information set FileName='{0}',Stime=GETDATE()  where loginName='{1}' and FileName='{2}'", FileNameTex.Text, Temp.TmeploginName, Temp.FileName));
			Temp.Update = true;
			NetworkStream stream = TcpClient.GetStream();//发送数据到服务端，服务端创建用户文件夹
			byte[] bytrArray = Encoding.Unicode.GetBytes("?" + Temp.TmeploginName + "\\" + FileNameTex.Text + "?" + Temp.TmeploginName + "\\" + DownloadFileName);
			stream.Write(bytrArray, 0, bytrArray.Length);


			FileInformation.Visible = false;
			KidRenovate();


		}

		private void listViewPic_Click(object sender, EventArgs e)
		{
			FileInformation.Visible = false;
		}

		private void listViewPic_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;

		}

		private void Hand_MouseDown(object sender, MouseEventArgs e)
		{
			FileInformation.Visible = false;

		}

		private void End_Click(object sender, EventArgs e)
		{
			FileInformation.Visible = false;

		}

		private void UserdataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
			
		}

		private void radioButton1_CheckedChanged(object sender, EventArgs e)
		{

		}

		private void UserPanel_Paint(object sender, PaintEventArgs e)
		{

		}

		private void UserFile_Click(object sender, EventArgs e)
		{
			
		}

		private void listViewPic_SelectedIndexChanged(object sender, EventArgs e)
		{

		}
		
		DataSet ds = new DataSet();
		private void ShowUser()
		{
			DBHelper.Conn.Close();			
			string connString = "server = 134.175.15.205;database = Webdisk;uid=sa;pwd=WHXL_whxl_1024";
			SqlConnection conn = new SqlConnection(connString);
			conn.Open();
			string sql = "select userId ,loginName ,loginPass ,StartTime ,isadmin  from userInfo";
			SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
			dap.Fill(ds);			
			conn.Close();
			conn.Dispose();
			DataTable dtProduct = ds.Tables[0];
			//UserdataGridView.DataSource = dt;
			
		}
		

		private void panel2_Paint(object sender, PaintEventArgs e)
		{

		}

        private void UserdataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DBHelper.Conn.Close();
            object count = DBHelper.ExecusteScalar("select COUNT(*)from userInfo");
            //MessageBox.Show(count+"");
            //获得当前选中的行   
            int rowindex = e.RowIndex;
            if (rowindex > int.Parse(count + "")-1)
            {
                panel2.Enabled = false;
                Submit.Enabled = false;
            }
            else
            {
                panel2.Enabled = true;
                Submit.Enabled = true;
            }

            try
            {
                TX_Name.Text = UserdataGridView.Rows[rowindex].Cells[0].Value.ToString();
                TX_Pass.Text = UserdataGridView.Rows[rowindex].Cells[1].Value.ToString().Trim();
                TX_StarTime.Text = UserdataGridView.Rows[rowindex].Cells[2].Value.ToString().Trim();
                SqlDataReader reader = null;
                DBHelper.InitConnection();
                DBHelper.Conn.Close();
                DBHelper.Conn.Open();
                string isadmin = "";
                string sql = string.Format("select isadmin,userId from userInfo where loginName='{0}'", TX_Name.Text);
                reader = DBHelper.GetDataReader(sql);
                while (reader.Read())
                {
                    isadmin = reader["isadmin"].ToString();
                    UserID = reader["userID"].ToString();
                }
                if (isadmin == "True")
                    radioButton1.Checked = true;
                else
                    radioButton2.Checked = true;
            }
            catch (Exception exc) { }
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void PalletIcon_Click(object sender, EventArgs e)
        {

        }

        private void PalletMenu_Opening(object sender, CancelEventArgs e)
        {
            
        }

        private void PalletMenu_Click(object sender, EventArgs e)
        {
            //this.WindowState = FormWindowState.Normal;
        }

        private void PalletMenu_DoubleClick(object sender, EventArgs e)
        {
            //this.WindowState = FormWindowState.Normal;
        }

        private void PalletMenu_MouseClick(object sender, MouseEventArgs e)
        {
            //this.WindowState = FormWindowState.Normal;
            if (this.WindowState == FormWindowState.Minimized)
                this.WindowState = FormWindowState.Normal;
        }

        private void PalletMenu_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //this.WindowState = FormWindowState.Normal;
            if (this.WindowState == FormWindowState.Minimized)
                this.WindowState = FormWindowState.Normal;
        }

        private void 个人信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Information IF = new Information();
            IF.ShowDialog();
        }
    }
}